﻿#pragma once

#include <vector>
#include <string>

namespace HadoopPipes {

  /**
   * 参见org.apache.hadoop.mapred.pipes.DownwardProtocol
   */
  class DownwardProtocol {
  public:
	/**
	 * Start communication
	 * @param protocol CURRENT PROTOCOL VERSION。目前只能为0
	 */
    virtual void start(int protocol) = 0;

	/**
   * Set the JobConf for the task.
   * @param values key1,value1,key2,value2
   */
    virtual void setJobConf(std::vector<std::string> values) = 0;

  /**
   * Set the input types for Maps.
   * @param keyType the name of the key's type
   * @param valueType the name of the value's type
   * @throws IOException
   */
    virtual void setInputTypes(std::string keyType, std::string valueType) = 0;
	/**
	 * Run a map task in the child.
	 * @param inputSplit The input split for this map.
	 * @param numReduces The number of reduces for this job.
	 * @param pipedInput Is the input coming from Java?
	 */
    virtual void runMap(std::string inputSplit, int numReduces, bool pipedInput)= 0;

	/**
	 * For maps with pipedInput(the input coming from Java), the key/value pairs are sent via this messaage.
	 * @param key The record's key
	 * @param value The record's value
	 * @throws IOException
	 */
    virtual void mapItem(const std::string& key, const std::string& value) = 0;
	/**
   * Run a reduce task in the child
   * @param reduce the index of the reduce (0 .. numReduces - 1)
   * @param pipedOutput is the output being sent to Java?
   * @throws IOException
   */
    virtual void runReduce(int reduce, bool pipedOutput) = 0;
	  /**
   * The reduce should be given a new key
   * @param key the new key
   * @throws IOException
   */
    virtual void reduceKey(const std::string& key) = 0;
	  /**
   * The reduce should be given a new value
   * @param value the new value
   * @throws IOException
   */
    virtual void reduceValue(const std::string& value) = 0;
	/**
   * Close the connection.
   */
    virtual void close() = 0;
	/**
   * The task should stop as soon as possible, because something has gone wrong.
   * @throws IOException
   */
    virtual void abort() = 0;
    virtual ~DownwardProtocol() {}
  };
}
